package com.app.piemoment;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.app.piemoment.entity.NotifyEntity;
import com.app.piemoment.image.ImageLoaderManager;

public class NotifyDetailActivity extends BaseActivity implements OnClickListener{
	
	private ListView listView;
	private ListAdapter adapter;
	private Button btn_menu;
	private TextView title_text;
	private Button btn_edit;
	
	public NotifyDetailActivity() {
		mainViewId = R.layout.notify;
	}
	
	@Override
	protected void initMainView() {
		initTitle(R.drawable.btn_back_bg,R.string.notify_title, 0,0);
		initComponents();
	}

	@Override
	protected void registerMainViewEvent() {
		// TODO Auto-generated method stub
	}

	@Override
	protected void processMainView() {
		// TODO Auto-generated method stub
		
	}


	private void initComponents() {
		listView = (ListView)findViewById(R.id.listView1);
		listView.setDividerHeight(0);
		listView.setCacheColorHint(Color.TRANSPARENT);
		adapter = new ListAdapter(this, getList());
		listView.setAdapter(adapter);
		
	}

	private ArrayList<NotifyEntity> getList() {
		ArrayList<NotifyEntity> list = new ArrayList<NotifyEntity>();
		NotifyEntity notify = new NotifyEntity();
		notify.setTitle("Blog推荐");
		notify.setDesc("haha");
		list.add(notify);
		list.add(notify);
		list.add(notify);
		return list;
	}
	public class ListAdapter extends BaseAdapter {

		private Context context;
		private ArrayList<NotifyEntity> list;
		private LayoutInflater listInflater;
		private ImageLoaderManager imageLoader;

		public ListAdapter(Context context, ArrayList<NotifyEntity> list) {
			imageLoader = new ImageLoaderManager(context, new Handler(), this);
			this.context = context;
			this.list = list;
		}

		@Override
		public int getCount() {
			return list != null ? list.size() : 0;
		}

		@Override
		public Object getItem(int arg0) {
			return null;
		}

		@Override
		public long getItemId(int arg0) {
			return 0;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			final ViewHolder holder;
			if (convertView == null) {
				listInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
				holder = new ViewHolder();
				convertView = this.listInflater.inflate(R.layout.notify_detail_item,null);
				
				holder.item = (LinearLayout) convertView.findViewById(R.id.notify_layout);
				holder.imgicon = (ImageView) convertView.findViewById(R.id.imageView);
				holder.username = (TextView) convertView.findViewById(R.id.username);
				holder.desc = (TextView) convertView.findViewById(R.id.desc);
				holder.timestamp = (TextView) convertView.findViewById(R.id.timestamp);
				holder.content = (TextView) convertView.findViewById(R.id.content);

				convertView.setTag(holder);
			} else {
				holder = (ViewHolder) convertView.getTag();
			}
			
			NotifyEntity notify = list.get(position);
			updateUI(holder,notify);
			return convertView;
		}

		private void updateUI(ViewHolder holder, NotifyEntity notify) {
//			holder.imgicon.setImageBitmap(imageLoader.getImage(notify.getImageUrl(), R.drawable.app_icon, 0));
			holder.username.setText(notify.getTitle());
			holder.desc.setText(notify.getDesc());
//			holder.timestamp.setText(notify.getCreateTime());
//			holder.content.setText(notify.getContent());
			
		}

		public final class ViewHolder {

			public LinearLayout item;
			public ImageView imgicon;
			public TextView username;
			public TextView desc;
			public TextView timestamp;
			public TextView content;

		}

	}
	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btn_left:
			super.onBackPressed();
			break;
		default:
			break;
		}
	}

}

